package com.example.transactiondemo.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;

@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    @Transactional(propagation = Propagation.REQUIRED)
    public void insertUserInfo(User user) throws SQLException {
        userDao.insertUserInfo(user);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void updateUser() throws SQLException {
        User userWoman = new User(133, "fjal", "女");
        User userman = new User(144, "jkolf", "男");
        insertUserInfo(userWoman);;
        insertUserInfo(userman);;
        int i = 1/0;
    }

//    @Transactional(propagation = Propagation.MANDATORY)
    public void insertUserInfo2(User user) throws SQLException {
        userDao.insertUserInfo(user);
    }

    @Transactional(propagation = Propagation.MANDATORY)
    public void updateUser2() throws SQLException {
        User userWoman = new User(133, "fjal", "女");
        User userman = new User(144, "jkolf", "男");
        insertUserInfo2(userWoman);;
        insertUserInfo2(userman);;
        int i = 1/0;
    }
}
